<?php
session_start();
      if (isset($_SESSION['k_username'])) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="/style.css" type="text/css" />
<title>Registrar Orden Nueva</title>
<link rel="stylesheet" type="text/css" media="all" href="../calendario/calendar-green.css" title="win2k-cold-1" /> 
 <!-- librería principal del calendario -->
 <script type="text/javascript" src="../calendario/calendar.js"></script>

 <!-- librería para cargar el lenguaje deseado -->
  <script type="text/javascript" src="../calendario/lang/calendar-es.js"></script>

  <!-- librería que declara la función Calendar.setup, que ayuda a generar un calendario en unas pocas líneas de código -->
  <script type="text/javascript" src="../calendario/calendar-setup.js"></script>    
<script type="text/javascript" src="../js/funciones.js"></script>   

<?php 

  include('conexion.inc.php');
  $link = Conectarse();
$categoria=$_GET[category];
mysql_select_db("gotica_ordencompras" ,$link);

?>
<script language="JavaScript"> 
function next_drop_down() 
{ 
i=document.ordenes.proveedor.selectedIndex; 
cat_val=document.ordenes.proveedor.options[i].value; 
location.href='nuevaorden.php?category='+cat_val; 
}
</script>
<div align="center" class="Estilo1">Registrar Orden  Nueva</div>
<form name="ordenes"  method="post" action="regordenes.php">
<table >
<tr>
<td>Proveedor</td>
<?php

$sql = "SELECT * FROM proveedor ORDER BY N_proveedor";
$result = mysql_query($sql, $link);
echo "<td ><select name=\"proveedor\" onchange=\"next_drop_down();\" />";
$es=0;
while ($row = mysql_fetch_array($result))
{
if (isset($categoria))
{
if($categoria==$row['idproveedor']){
echo "<option selected value=\"".$row['idproveedor']."\">";
echo $row['N_proveedor'];
echo "</option>";	
	}else{
		echo "<option value=\"".$row['idproveedor']."\">";
echo $row['N_proveedor'];
echo "</option>";}}else{
echo "<option value=\"".$row['idproveedor']."\">";
echo $row['N_proveedor'];
echo "</option>";}
}
echo "</select></td>";
 ?>
</tr>
<tr>
<td>Cliente</td>
<?php
$sql = "SELECT * FROM cliente";
$result = mysql_query($sql, $link);
echo "<td ><select name=\"cliente\" />";

while ($row = mysql_fetch_array($result))
{
echo "<option value=\"".$row['idcliente']."\">";
echo $row['N_Cliente'];
echo "</option>";
}
echo "</select></td>";
 ?>
</tr>
<tr>
<td>Area</td>
<?php
$sql = "SELECT * FROM Area";
$result = mysql_query($sql, $link);
echo "<td ><select name=\"area\" />";

while ($row = mysql_fetch_array($result))
{
echo "<option value=\"".$row['idarea']."\">";
echo $row['area'];
echo "</option>";
}
echo "</select></td>";
 ?>
</tr>
<tr>
<td>Autoriza</td>
<?php
$sql = "SELECT * FROM Gestionador";
$result = mysql_query($sql, $link);
echo "<td ><select name=\"autoriza\" />";

while ($row = mysql_fetch_array($result))
{
echo "<option value=\"".$row['idgestionador']."\">";
echo $row['Gestionador'];
echo "</option>";
}
echo "</select></td>";
 ?>
</tr>
<tr>

    <td>Fecha Pedido</td>
  
<?php 
echo " <td> <input type=\"text\" id=\"fechapedido\" value=".date("y-m-d")." name=\"fechapedido\" size=\"10\"  /><input type=\"button\"  value=\"...\" onclick=\"return showCalendar('fechapedido', '%Y-%m-%d' , '24', true);\" />";
?>
   </td>
</tr>
<tr>
<td>
<fieldset>
<legend>Observaciones</legend>
<textarea name="observaciones" rows="10" cols="30" > </textarea>
</fieldset></td></tr>
<?php 
echo "<tr>";
echo "<td> ";
echo "<table>";
echo "<tr>";
echo "<td> Producto </td> ";
echo "<td >Cantidad</td>";
echo "<td> Unidad </td> ";
echo "</tr>";
for ($i=1;$i<=10;$i++){
echo "<tr>";

$sql = "SELECT producto.* FROM producto, prod_provdo, proveedor where producto.idproducto=prod_provdo.idproducto and prod_provdo.idproveedor=$categoria and  proveedor.idproveedor=prod_provdo.idproveedor Order BY producto.n_producto";
$result = mysql_query($sql, $link);
echo "<td ><select name=\"producto[]\" />";

while ($row = mysql_fetch_array($result))
{
echo "<option value=\"".$row['idproducto']."\">";
echo $row['n_producto'];
echo "</option>";
}
echo "</select></td>";
echo "<td > <input type=\"text\" name=\"cantidad[]\" size=\"10\" />";
echo "</td>";

$sql = "SELECT * FROM unidad";
$result = mysql_query($sql, $link);
echo "<td ><select name=\"unidad[]\" />";

while ($row = mysql_fetch_array($result))
{
echo "<option value=\"".$row['idunidad']."\">";
echo $row['n_unidad'];
echo "</option>";
}
echo "</select></td>";
echo "</tr>";
}
echo "</table></td></tr>";
?>
<tr>
<td>
<input type="submit" value="enviar" name="enviar"  />
</td>
<td>
<input type="reset" value="Limpiar" />
</td>
</tr>
</table>
</form>
<div align="center" >
<a href="/ordenes.php">Inicio</a></div>
</body>
</html>
<?
}else
{
	echo "<SCRIPT LANGUAGE=\"javascript\">";
echo "location.href = \"index.php\"";
echo "</SCRIPT>";
	}
?>